package com.hzlx.mesMaterialTransactions.controller;

import java.util.List;
import java.io.IOException;

import com.hzlx.MesMaterialTransactionsDto;
import com.hzlx.mesMaterialTransactions.domain.OperationWithMaterial;
import com.hzlx.mesMaterialTransactions.mapper.MesMaterialTransactionsMapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.mesMaterialTransactions.domain.MesMaterialTransactions;
import com.hzlx.mesMaterialTransactions.service.IMesMaterialTransactionsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * MES 物料交易，记录物料入库、出库等交易全流程信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/inventory")
public class MesMaterialTransactionsController extends BaseController
{
    @Autowired
    private IMesMaterialTransactionsService mesMaterialTransactionsService;
@Resource
private MesMaterialTransactionsMapper mesMaterialTransactionsMapper;
    /**
     * 查询MES 物料交易，记录物料入库、出库等交易全流程信息列表
     */
    @RequiresPermissions("material-service:inventory:transactions:list")
    @GetMapping("/transactions/list")
    public TableDataInfo list(MesMaterialTransactions mesMaterialTransactions)
    {
        startPage();
        List<MesMaterialTransactions> list = mesMaterialTransactionsService.selectMesMaterialTransactionsList(mesMaterialTransactions);
        return getDataTable(list);
    }

    /**
     * 导出MES 物料交易，记录物料入库、出库等交易全流程信息列表
     */
    @RequiresPermissions("material-service:inventory:transactions:export")
    @Log(title = "MES 物料交易，记录物料入库、出库等交易全流程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/transactions/export")
    public void export(HttpServletResponse response, MesMaterialTransactions mesMaterialTransactions)
    {
        List<MesMaterialTransactions> list = mesMaterialTransactionsService.selectMesMaterialTransactionsList(mesMaterialTransactions);
        ExcelUtil<MesMaterialTransactions> util = new ExcelUtil<MesMaterialTransactions>(MesMaterialTransactions.class);
        util.exportExcel(response, list, "MES 物料交易，记录物料入库、出库等交易全流程信息数据");
    }

    /**
     * 获取MES 物料交易，记录物料入库、出库等交易全流程信息详细信息
     */
    @RequiresPermissions("material-service:inventory:transactions:query")
    @GetMapping(value = "/transactions/{transactionId}")
    public AjaxResult getInfo(@PathVariable("transactionId") Long transactionId)
    {
        return success(mesMaterialTransactionsService.selectMesMaterialTransactionsByTransactionId(transactionId));
    }

    /**
     * 新增MES 物料交易，记录物料入库、出库等交易全流程信息
     */
    @RequiresPermissions("material-service:inventory:transactions:add")
    @Log(title = "MES 物料交易，记录物料入库、出库等交易全流程信息", businessType = BusinessType.INSERT)
    @PostMapping("/transactions")
    public AjaxResult add(@RequestBody MesMaterialTransactions mesMaterialTransactions)
    {
        return toAjax(mesMaterialTransactionsService.insertMesMaterialTransactions(mesMaterialTransactions));
    }
    @PostMapping("/transactionsDto")
    public AjaxResult addByRecord(@RequestBody MesMaterialTransactionsDto mesMaterialTransactionsDto)
    {
        MesMaterialTransactions mesMaterialTransactions=new MesMaterialTransactions();
        BeanUtils.copyProperties(mesMaterialTransactionsDto,mesMaterialTransactions );
        return toAjax(mesMaterialTransactionsService.insertMesMaterialTransactions(mesMaterialTransactions));
    }
    /**
     * 修改MES 物料交易，记录物料入库、出库等交易全流程信息
     */
    @RequiresPermissions("material-service:inventory:transactions:edit")
    @Log(title = "MES 物料交易，记录物料入库、出库等交易全流程信息", businessType = BusinessType.UPDATE)
    @PutMapping("/transactions")
    public AjaxResult edit(@RequestBody MesMaterialTransactions mesMaterialTransactions)
    {
        return toAjax(mesMaterialTransactionsService.updateMesMaterialTransactions(mesMaterialTransactions));
    }

    /**
     * 删除MES 物料交易，记录物料入库、出库等交易全流程信息
     */
    @RequiresPermissions("material-service:inventory:transactions:remove")
    @Log(title = "MES 物料交易，记录物料入库、出库等交易全流程信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/transactions/{transactionIds}")
    public AjaxResult remove(@PathVariable Long[] transactionIds)
    {
        return toAjax(mesMaterialTransactionsService.deleteMesMaterialTransactionsByTransactionIds(transactionIds));
    }



    @GetMapping("/transactionsToShow")
    public List<OperationWithMaterial> findAllShow(){
        return mesMaterialTransactionsMapper.selectAllGroupByOperation();
    }
}
